﻿using DDD.Domain;
using System;
using System.Linq;
using System.Linq.Expressions;

namespace DDD.Application
{
    public class BaseService<T> : IBaseService<T> where T : class
    {
        public IBaseRepository<T> _IBaseRepository;
        public BaseService(IBaseRepository<T> IBaseRepository)
        {
            _IBaseRepository = IBaseRepository;
        }
        void IBaseService<T>.Add(T entity)
        {
            _IBaseRepository.Add(entity);
        }

        void IBaseService<T>.Delete(Expression<Func<T, bool>> exp)
        {
            _IBaseRepository.Delete(exp);
        }

        void IBaseService<T>.Delete(T entity)
        {
            _IBaseRepository.Delete(entity);
        }

        IQueryable<T> IBaseService<T>.Find(Expression<Func<T, bool>> exp)
        {
            return _IBaseRepository.Find(exp);
        }

        IQueryable<T> IBaseService<T>.Find(int pageindex, int pagesize, Expression<Func<T, bool>> exp)
        {
            return _IBaseRepository.Find(pageindex,pagesize,exp);
        }

        int IBaseService<T>.GetCount(Expression<Func<T, bool>> exp)
        {
            return _IBaseRepository.GetCount(exp);
        }

        T IBaseService<T>.GetSingle(Expression<Func<T, bool>> exp)
        {
            return _IBaseRepository.GetSingle(exp);
        }

        void IBaseService<T>.Update(T entity)
        {
             _IBaseRepository.Update(entity);
        }

        void IBaseService<T>.Update(Expression<Func<T, bool>> exp, T entity)
        {
            _IBaseRepository.Update(exp,entity);
        }
    }
}
